﻿@{
 ViewBag.Title = "Creating a ASP MVC CRUD application";
 Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Creating a ASP MVC CRUD application</h2>
<h3>Approaches to creating entity framework within an  MVC application</h3>
<p>When we want to work with entity framework within an MVC  application there are three different approaches you can take:</p>
<ol>
<li>Model first: We create entity framework from existing models</li>
<li>Database first: We create entity framework from an existing database</li>
<li>Code first: We create entity framework by creating the classes we need first, then associate the database based on these needs</li>
</ol>
<p>For our purposes, we’ll be using code first approach.</p>
<h3>Creation of applicant database</h3>
<p>Before creating our data model in our  MVC application, let’s create our database and corresponding table. Follow these steps:</p>
<ol>
<li>From the desktop, left click the start button</li>
<li>In the search field type sql server</li>
<li>Choose Microsoft SQL Server Management Studio from the start menu:</li>
</ol>
<p align="center"><img src="@Url.Content("~/Content/aspmvccrud/images/start_menu_sql.jpg")" width="230" height="421" /></p>
<ol start="4">
<li>
In the Connect to Server window:
<ol type="a">
 <li>Choose a local computer database</li>
 <li>For authentication, leave Windows Authentication</li>
 <li>Left click Connect:</li>
</ol>
</li>
</ol>
<p align="center"><a href="@Url.Content("~/content/aspmvccrud/images/connect_server_sql.jpg")" data-lightbox="Connect Sql Server"><img src="@Url.Content("~/content/aspmvccrud/images/thumbs/connect_server_sql.jpg")" alt="Connect Sql Server" width="300" height="221" /></a></p>
<ol start="5">
<li>From object explorer, left click to expand Databases:</li>
</ol>
<p align="center"><img src="@Url.Content("~/Content/aspmvccrud/images/expand_databases_object_explorer.jpg")" width="191" height="73" /></p>
<ol start="6">
<li>Right click Databases, and choose New Database:</li>
</ol>
<p align="center"><img src="@Url.Content("~/Content/aspmvccrud/images/create_new_db_object_explorer.jpg")" width="317" height="74" /></p>
<ol start="7">
<li>
In New Database window, in Database name text field:
<ol type="a">
 <li>Type Applicant</li>
 <li>Left click OK</li>
</ol>
</li>
</ol>
<p align="center"><a href="@Url.Content("~/content/aspmvccrud/images/create_new_db_details.jpg")" data-lightbox="Create New Database Details"><img src="@Url.Content("~/content/aspmvccrud/images/thumbs/create_new_db_details.jpg")" alt="Create New Database Details" width="300" height="309" /></a></p>
<h3>Creation of applicants table</h3>
<p>With our database created, let’s create our table for applicant submissions:</p>
<ol>
<li>From Object Explorer, left click to expand Applicant database:</li>
</ol>
<p align="center"><img src="@Url.Content("~/Content/aspmvccrud/images/expand_applicant.jpg")" width="172" height="61" /></p>
<ol start="2">
<li>Right click on Tables, and choose New: Table…:</li>
</ol>
<p align="center"><a href="@Url.Content("~/content/aspmvccrud/images/create_table.jpg")" data-lightbox="Create Table"><img src="@Url.Content("~/content/aspmvccrud/images/thumbs/create_table.jpg")" alt="Create Table" width="300" height="67" /></a></p>
<ol start="3">
<li>From the tab that opens, enter the following columns:</li>
</ol>
<table cellspacing="0" class="crud">
<tr>
<td>Column Name</td>
<td>Data Type</td>
<td>Primary Key</td>
<td>Identity Seed</td>
<td>Allow Nulls</td>
</tr>
<tr>
<td>ApplicantId</td>
<td>Int</td>
<td>Yes</td>
<td>Yes</td>
<td>No</td>
</tr>
<tr>
<td>FirstName</td>
<td>Varchar(50)</td>
<td>No</td>
<td>No</td>
<td>No</td>
</tr>
<tr>
<td>LastName</td>
<td>Varchar(50)</td>
<td>No</td>
<td>No</td>
<td>No</td>
</tr>
<tr>
<td>City</td>
<td>Varchar(50)</td>
<td>No</td>
<td>No</td>
<td>No</td>
</tr>
<tr>
<td>State</td>
<td>Varchar(50)</td>
<td>No</td>
<td>No</td>
<td>No</td>
</tr>
<tr>
<td>ZipCode</td>
<td>Varchar(5)</td>
<td>No</td>
<td>No</td>
<td>No</td>
</tr>
</table>
<p>Once finished let’s save our table:</p>
<ol>
<li>From the main menu, choose File: Save Table_1:</li>
</ol>
<p align="center"><img src="@Url.Content("~/Content/aspmvccrud/images/save_table.jpg")" width="315" height="215" /></p>
<ol start="2">
<li>
In Choose Name window:
<ol type="a">
 <li>Type Applicants</li>
 <li>Left click OK:</li>
</ol>
</li>
</ol>
<p align="center"><a href="@Url.Content("~/content/aspmvccrud/images/choose_table_name.jpg")" data-lightbox="Choose Table Name"><img src="@Url.Content("~/content/aspmvccrud/images/thumbs/choose_table_name.jpg")" alt="Choose Table Name" width="300" height="107" /></a></p>
<p>Note: As a reader, you may be wondering why we chose Applicant as our database name, while we chose Applicants as our table name? The answer is simple &#8212; by default, entity framework uses pluralization on table names. If we want to remove pluralization, a Google search would provide examples on a resolution.</p>
<p>We'll continue next with  @Html.ActionLink("creation of model", "Index3").</p>